home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games: Greatest Hits 1996 / Amiga Games: Greatest Hits 1996.iso / archive / userbox / publicdomain / engclock_v7.0.lha / EngClock_v7.0 / EngClock7_Source / locale.c < prev    next >
C/C++ Source or Header  |  1995-12-05  |  4KB  |  161 lines

  1. /* Get the locale settings */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <libraries/locale.h>
  7. #include <libraries/iffparse.h>
  8. #include <libraries/dos.h>
  9. //#include <proto/locale.h>
  10. //#include <proto/iffparse.h>
  11. //#include <proto/dos.h>
  12. #include <prefs/locale.h>
  13. #include <prefs/prefhdr.h>
  14.  
  15. #include <clib/dos_protos.h>
  16. #include <clib/iffparse_protos.h>
  17.  
  18. #define ENGLISH 1
  19. #define FRENCH 2
  20. #define SPANISH 3
  21.  
  22. extern int language;
  23. extern BOOL locale;
  24.  
  25. extern struct IntuitionBase *IntuitionBase;
  26. extern struct GfxBase *GfxBase;
  27. extern struct Library *UtilityBase;
  28. extern struct Library *GadToolsBase;
  29. extern struct Library *DiskfontBase;
  30. extern struct Library *AslBase;
  31. extern struct Library *IFFParseBase;
  32. extern struct Library *DOSBase;
  33.  
  34. struct Event {
  35.     BOOL used;
  36.     int type;    /* Type of event */
  37.     int hours;    /* Time of event */
  38.     int minutes;
  39.     int timecode;
  40.     char message[256];
  41.     int day;
  42.     int month;
  43.     int year;
  44.     BOOL enabledate;
  45.     int freq;
  46. };
  47.  
  48. extern struct {
  49. /* Prefs structure used for preferences file format */
  50.  
  51.    char header[10];  /* I.D. Header */
  52.    int vers;         /* Version of preferences file */
  53.    int x;            /* X dimension of window when saved */
  54.    int y;            /* Y dimension of window when saved */
  55.    int width;        /* Width of window when saved */
  56.    int height;       /* Height of window when saved */
  57.    int planguage;    /* Language selected (menu) when saved, low pri */
  58.    int just;         /* Justification of text, 0=Left, 1=Centre, 2=Right */
  59.    short date;       /* Display date?, 0 = No, 1=Yes */
  60.    short wtf;         /* Window to front ? */
  61.    int time_col[8];
  62.    int date_col[8];
  63.    short autoadjust;       /* Use automatic adjustment on window ? */
  64.    char backdrop[256];  /* Backdrop image */
  65.    char pub[139];            /* Default public screen */
  66.     char accent[256];        /* Language file for tRanslate */
  67.     char tkey[100];
  68.     char hkey[100];
  69.     struct Event events[11];  /* For the alarm! */
  70.  
  71. }prefs;
  72.  
  73. short getlocale(void);
  74.  
  75. short getlocale(void) {
  76.     int i=0, p=0;
  77.     struct IFFHandle *iffhandle;
  78.     struct ContextNode *cnode;
  79.     struct StoredProperty *hdrsp, *sp;
  80.     LONG ifferror;
  81.     char prefs_languages[10][31];
  82.     
  83.     IFFParseBase=OpenLibrary("iffparse.library",0);
  84.     if(!IFFParseBase)
  85.         goto skipbit;
  86.     
  87.     if(iffhandle=AllocIFF()) {
  88.         if(iffhandle->iff_Stream=(LONG)Open("env:sys/locale.prefs",MODE_OLDFILE)) {
  89.             InitIFFasDOS(iffhandle);
  90.             if(OpenIFF(iffhandle,IFFF_READ) == 0) {
  91.                 PropChunk(iffhandle,ID_PREF,ID_PRHD);
  92.                 PropChunk(iffhandle,ID_PREF,ID_LCLE);
  93.                 while(1) {
  94.                     ifferror=ParseIFF(iffhandle,IFFPARSE_STEP);
  95.                     if(ifferror==IFFERR_EOC) continue; else if(ifferror) break;
  96.                     if(cnode=CurrentChunk(iffhandle)) {
  97.                        if(cnode->cn_ID == ID_PRHD || cnode->cn_ID == ID_FORM) continue;
  98.                     }
  99.                     
  100.                     hdrsp=FindProp(iffhandle,ID_PREF,ID_PRHD);
  101.                     if(sp=FindProp(iffhandle,ID_PREF,ID_LCLE)) {
  102.                         for(i=0; i<10; i++) {
  103.                             strcpy(prefs_languages[i],((struct LocalePrefs *)sp->sp_Data)->lp_PreferredLanguages[i]);
  104.                         }
  105.                     }
  106.                 }
  107.                 CloseIFF(iffhandle);
  108.             }
  109.             Close(iffhandle->iff_Stream);
  110.         }
  111.         FreeIFF(iffhandle);
  112.     }
  113.  
  114.     CloseLibrary(IFFParseBase);
  115.  
  116.     /* Additional Processing */
  117.     
  118.     for(p=0; p<10; p++) {
  119.         if(!strcmp(prefs_languages[p],"english")) {
  120.             language=ENGLISH; 
  121.             return(1);
  122.         }
  123.         if(!strcmp(prefs_languages[p],"français")) {
  124.             language=FRENCH;
  125.             return(1);
  126.         }
  127.         if(!strcmp(prefs_languages[p],"español")) {
  128.             language=SPANISH; 
  129.             return(1); 
  130.         }
  131.     }            
  132.     
  133.     /* If it gets this far then none of the preferred languages is
  134.        supported.  In this case the built-in system is set */
  135.  
  136.     skipbit:
  137.  
  138.    language=prefs.planguage;
  139.     locale=FALSE;
  140.  
  141.    /* If nothing is found in planguage (such as when a new pref file is
  142.       created) then English is set to the prefs and system */
  143.  
  144.     if(!language) {
  145.         language=ENGLISH; prefs.planguage=ENGLISH;
  146.     }
  147.     
  148.     return(0);    /* Locale did not work */
  149. }
  150.                     
  151.                         
  152.                 
  153.         
  154.  
  155.     
  156.     
  157.  
  158.  
  159.  
  160.  
  161.